package com.universalInterface.lims_interface.controller;


import cn.hutool.core.bean.BeanUtil;
import com.universalInterface.common.result.ApiResult;
import com.universalInterface.lims_interface.entity.LabChannel;
import com.universalInterface.lims_interface.service.ILabChannelService;
import com.universalInterface.lims_interface.vo.labchannel.LabChannelDeleteVo;
import com.universalInterface.lims_interface.vo.labchannel.LabChannelSaveVo;
import com.universalInterface.lims_interface.vo.labchannel.LabChannelUpdateVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 实验室通道
 * </p>
 *
 * @author author
 * @since 2023-12-19
 */
@Tag(name = "实验室通道")
@Validated
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/labChannel")
public class LabChannelController {

	private final ILabChannelService iLabChannelService;

	@Operation(summary = "新增实验室通道")
	@PostMapping("/save")
	public ApiResult save(@Parameter(name = "LabChannelSaveVo", description = "实验室通道新增对象") @Valid @RequestBody LabChannelSaveVo saveVo) {
		LabChannel labChannel = iLabChannelService.save(BeanUtil.copyProperties(saveVo, LabChannel.class));
		return ApiResult.success("新增成功！");
	}

	@Operation(summary = "通过id更新实验室通道")
	@PutMapping("/updateById")
	public ApiResult updateById(@Parameter(name = "LabChannelUpdateVo", description = "实验室通道更新对象") @Valid @RequestBody LabChannelUpdateVo updateVo) {
		Integer i = iLabChannelService.updateById(BeanUtil.copyProperties(updateVo, LabChannel.class));
		return ApiResult.success("更新成功！size = " + i);
	}

	@Operation(summary = "通过id删除实验室通道")
	@DeleteMapping("/deleteById")
	public ApiResult deleteById(@Parameter(name = "id", description = "主键id") @NotNull @RequestParam(value = "id") Long id) {
		Integer i = iLabChannelService.deleteById(id);
		return ApiResult.success("删除成功！size = " + i);
	}

	@Operation(summary = "批量新增实验室通道")
	@PostMapping("/saveBatch")
	public ApiResult saveBatch(@Parameter(name = "LabChannelSaveVo", description = "实验室通道新增对象") @Valid @RequestBody List<LabChannelSaveVo> saveVoList) {
		Integer i = iLabChannelService.saveBatch(BeanUtil.copyToList(saveVoList, LabChannel.class));
		return ApiResult.success("新增成功！size = " + i);
	}

	@Operation(summary = "通过其他字段条件删除实验室通道数据")
	@PostMapping("/delete")
	public ApiResult delete(@Parameter(description = "实验室通道删除参数") @Valid @RequestBody LabChannelDeleteVo deleteVo) {
		Integer i = iLabChannelService.delete(BeanUtil.copyProperties(deleteVo, LabChannel.class));
		return ApiResult.success("删除成功！size = " + i);
	}


}
